package com.lc.pianostudent.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;


import com.lc.pianostudent.R;
import com.zcx.helper.glide.GlideLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/5/10.
 */

public class GridAdapter extends BaseAdapter{

    private List<String> mimglist = new ArrayList<String>();

    private LayoutInflater mInflater;
    private Context mContext;
//    LinearLayout.LayoutParams params;

    public GridAdapter(Context context, List<String> imglist) {
        mimglist = imglist;
        mContext = context;
        mInflater = LayoutInflater.from(context);

//        params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//        params.gravity = Gravity.CENTER;
    }

    public int getCount() {
        return mimglist.size();
    }

    public Object getItem(int position) {
        return mimglist.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;

        if (convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_gridview,null);

            viewHolder.img= (ImageView) convertView.findViewById(R.id.grid_icon);

            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        GlideLoader.getInstance().get(mimglist.get(position),viewHolder.img);

        return convertView;
    }

    class ViewHolder{

        public ImageView img;
    }

}
